package cn.FagDegrn.chatbot.api.test;

import cn.FagDegrn.chatbot.api.domain.ai.IOpenAI;
import cn.FagDegrn.chatbot.api.domain.zsxq.IzsxqApi;
import cn.FagDegrn.chatbot.api.domain.zsxq.model.aggregates.UnansweredAggregates;
import cn.FagDegrn.chatbot.api.domain.zsxq.model.vo.Topics;
import cn.FagDegrn.chatbot.api.domain.zsxq.service.ZsxqApi;
import cn.hutool.json.JSONObject;
import com.alibaba.fastjson.JSON;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.json.Json;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringBootRunTest {
    private Logger logger = LoggerFactory.getLogger(SpringBootRunTest.class);

    @Value("${chatai-api.groupId}")
    private String groupId;
    @Value("${chatai-api.cookie}")
    private String cookie;

    @Resource
    private IzsxqApi zsxqApi;

    @Resource
    private IOpenAI openAI;

    @Test
    public void test_zsxqApi() throws IOException {
        UnansweredAggregates unansweredAggregates = zsxqApi.queryUnansweredQuestionTopicId(groupId, cookie);
        logger.info("测试结果:{}", JSON.toJSONString(unansweredAggregates));

        List<Topics> topics = unansweredAggregates.getResp_data().getTopics();
        for (Topics topic : topics) {
            String topicId = topic.getTopic_id();
            String text = topic.getQuestion().getText();

            logger.info("topicId:{},text:{}",topicId,text);

            zsxqApi.answer(groupId,cookie,topicId,text,false);
        }
    }


    @Test
    public void test_openAi() throws IOException {
        String result = openAI.doChatGPT("");
        logger.info("执行结果:"+result);
    }
}
